import React, { Component } from 'react'
import './TodoHeader.css';
import store from '../../redux/store';
import {todoAddAction} from '../../redux/actions/todoActions';

export default class TodoHeader extends Component {
    render() {
        return (
            <div className="todo-header">
                <input
                    type="text"
                    placeholder="请输入你的任务名称，按回车键确认"
                    onKeyDown={this.handleKeyDown}
                />
            </div>
        )
    }

    handleKeyDown = (e) => {
        if(e.keyCode === 13){
            store.dispatch(todoAddAction(e.target.value));
        }
    }
}
